package com.dt76.smallloanbackenduser.controller.etao;


import com.dt76.smallloanbackenduser.remote.etao.EmployeeRemote;
import com.dt76.smallloanbackenduser.remote.etao.SLogRemote;
import com.dt76.smallloanbackenduser.utils.Page;
import com.dt76.smallloanbackenduser.utils.Result;
import groovy.util.IFileNameFinder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/sLog")
public class SLogController {

    @Autowired
    private SLogRemote sLogRemote;
    @Autowired
    private EmployeeRemote employeeRemote;

    //查看操作日志
    @RequestMapping("/getSLog")
    public String getSLog(Model model,
                          @RequestParam(defaultValue = "1", value = "pageNum") Integer pageNum,
                          @RequestParam(defaultValue = "0", value = "eId") Integer eId,
                          @RequestParam(defaultValue = "", value = "startTime") String startTime) {
        if (startTime.equals("0")) {
            startTime = "";
        }
        Page page = sLogRemote.getPageSLog(pageNum, eId, startTime);
        model.addAttribute("pageInfo", page);
        model.addAttribute("logs", page.getRows());
        model.addAttribute("selEId", eId);
        model.addAttribute("startTime", startTime);
        model.addAttribute("allEmp", employeeRemote.getAllEmp());
        List<Integer> pageArr = new ArrayList<Integer>();
        for (Integer i = 0; i < page.getTotalPageCount(); i++) {
            pageArr.add(i + 1);
        }
        model.addAttribute("pageArr", pageArr);
        return "pages/etao/SLogManage";
    }



    //带条件查询
    @RequestMapping("/getSLogBy")
    @ResponseBody
    public String selectPageBy(Integer pageNum,Integer eId,String startTime) {
        return "/sLog/getSLog?pageNum=" + pageNum + "&eId=" + eId + "&startTime=" + startTime;
    }

    //删除By操作日期
    @RequestMapping("/delByTime")
    @ResponseBody
    public Result delByTime(String delTime) {
        Result result = sLogRemote.delSLogByTime(delTime);
        if (result.isSuccess()) {
            result.setMsg("删除成功");
        } else {
            result.setMsg("删除失败");
        }
        return result;
    }




}
